package top.humbleyuan.test;

import java.util.*;

/**
 * @Author HumbleYuan
 * @Date 2020/4/7 19:33
 * @Des
 */
public class WangYiExamDemo {
    public static void main(String[] args) {

        m1();
        //m2();
        
//        Scanner sc = new Scanner(System.in);
//
//        while(sc.hasNext()) {
//            int n = sc.nextInt();
//            int m = sc.nextInt();
//
//        }
//
//        sc.close();
    }

    private static void m2() {
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()) {
            int n = sc.nextInt();
            int D = sc.nextInt();
            sc.nextLine();

            List<monster> monstersByPf = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                monstersByPf.add(new monster());
                monstersByPf.get(i).pf = sc.nextInt();
            }
            //sc.nextLine();

            List<monster> monstersByDa = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                monstersByPf.get(i).sh = sc.nextInt();
                monstersByDa.add(monstersByPf.get(i));
            }

            Collections.sort(monstersByPf, (m1, m2) -> {
                if(m1.pf < m2.pf) {
                    return -1;
                } else if(m1.pf > m2.pf) {
                    return 1;
                } else {
                    return 0;
                }
            });

            Collections.sort(monstersByDa, (m1, m2) -> {
                if(m1.sh < m2.sh) {
                    return -1;
                } else if(m1.sh > m2.sh) {
                    return 1;
                } else {
                    if(m1.pf > m2.pf) {
                        return -1;
                    } else if(m1.pf < m1.pf) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });


            int damage = 0;
            while (monstersByPf.size() > 0) {
                if(D > monstersByPf.get(0).pf) {
                    monster min = monstersByPf.get(0);
                    monstersByPf.remove(0);
                    monstersByDa.remove(min);
                    D++;
                } else {
                    monster min = monstersByDa.get(0);
                    monstersByDa.remove(0);
                    monstersByPf.remove(min);
                    damage += min.sh;
                    D++;
                }
            }

            System.out.println(damage);

        }

        sc.close();
    }

    static class monster {
        public int pf;
        public int sh;

        @Override
        public String toString() {
            return "monster{" +
                    "pf=" + pf +
                    ", sh=" + sh +
                    '}';
        }
    }

    private static void m1() {
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()) {
            int n = Integer.valueOf(sc.nextLine());

            int[] nums = new int[n];
            int[] res = new int[n - 1];

            int d = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                nums[i] = sc.nextInt();
                if(i > 0) {
                    res[i -1] = nums[i] - nums[i - 1];
                    if(res[i - 1] <= 0) {
                        d = -1;
                    }
                }
            }

            if(d == -1) {
                System.out.println(-1);
                return;
            }

            for (int i = 0; i < res.length - 1; i++) {
                for (int j = i + 1; j < res.length; j++) {
                    int curD = commonDivisor(res[i], res[j]);
                    d = Math.min(d, curD);
                }

            }
            System.out.println(d);

            sc.nextLine();

        }

        sc.close();
    }

    public static int commonDivisor(int num1,int num2) {

        if(num1 == num2) {
            return num1;
        }

        int min = Math.min(num1, num2);
        int div = 1;
        // 先找到所有公因数约去
        for (int i = 1; i <= min; i++) {
            // 计算最大公因数
            if(num1 % i == 0 && num2 % i == 0) {
                div = i;
            }
        }

        // 最小公倍数
        return div;
    }
}
